import router, { asyncRoutes, constantRoutes } from './router'
import store from './store'
import sdk from 'igw-library/lib/sdk'
import { settingRouteName, tree } from '@/utils/routeNameSetting'
let asyncRouterMap = [...constantRoutes, ...asyncRoutes]
const whiteList = ['/integratedQuery/fundList', '/integratedQuery/fundInfo'] // 白名单
const getRolesApi = function () {
	const list = ['fundInfo', 'fundList']
	const locationListStr = document.location.pathname.split('/')[document.location.pathname.split('/').length - 1]
	if (!list.includes(locationListStr)) {
		return new Promise(async (resolve, reject) => {
			await store.dispatch('user/getInfo').then(res => {
				if (res.roles.length) {
					const mockPermissionData = { permissionList: [...new Set([...res.roles])] }
					const list = tree(res.menuList, [])
					asyncRouterMap = settingRouteName(list, asyncRouterMap)
					resolve(mockPermissionData)
				}
			})
		})
	} else {
		return new Promise((resolve) => {
			resolve({ permissionList: [] })
		})
	}
}

sdk.permission({
	router,
	asyncRouterMap,
	whiteList,
	getRolesApi
})
